package jucTest;

public class Resouces {
    private int i=0;
    public synchronized void increment() throws InterruptedException {
        System.out.println(Thread.currentThread().getName()+"==>"+"进入判断");
        while(i!=0){
            System.out.println(Thread.currentThread().getName()+"==>"+"进入开始等待");
            this.wait();
            System.out.println(Thread.currentThread().getName()+"==>"+"等待结束");
        }
        i++;
        System.out.println(Thread.currentThread().getName()+"==>"+i);
        this.notify();
    }

    public synchronized void decrement() throws InterruptedException {
        System.out.println(Thread.currentThread().getName()+"==>"+"进入判断");
        while(i==0){
            System.out.println(Thread.currentThread().getName()+"==>"+"进入开始等待");
            this.wait();
            System.out.println(Thread.currentThread().getName()+"==>"+"等待结束");
        }
        i--;
        System.out.println(Thread.currentThread().getName()+"==>"+i);
        this.notify();
    }
}
